
#ifndef READER_H
#define READER_H

#ifndef STRINGFILE_H
#include"StringFile.h"
#endif

class Reader :public StringFile {
	ifstream in;
public:
	Reader();
	Reader(string);
	bool open(string locate);
	bool close();
	string read();
};

inline Reader::Reader()
{
	this->StringFile::StringFile();
}

inline Reader::Reader(string locate)
{
	if (this->open(locate) == false)
		isClose = true;
	else
		isClose = false;
}

inline bool Reader::open(string locate)
{
	in.open(locate.c_str(), ios::_Nocreate);
	if (!in)
	{
		cout << "无法打开文件" << locate << "！" << endl;
		isClose = true;
		return false;
	}
	PATH = locate;
	isClose = false;
	return true;
}

inline bool Reader::close()
{
	if (!isClose)
	{
		in.close();
		isClose = true;
		return true;
	}
	else
		return false;
}

inline string Reader::read()
{
	string str;
	do {
		getline(in, str);
	} while (str.empty() && !in.eof());
	return str;
}

#endif 
